package mwn.droidbus.connection;

import java.util.ArrayList;

import com.google.android.maps.GeoPoint;

import mwn.droidbus.elements.Bus;
import mwn.droidbus.elements.BusStop;
import mwn.droidbus.elements.Route;

public class TestData implements InformationUpdater {

	private int b1lat = -34924470;
	private int b1long = 138597197;
	private int b2lat = -34925464;
	private int b2long = 138599688;
	private int b3lat = -34922724;
	private int b3long = 138599527;

	private static int moveme = 0;

	Route ninetynineccwise;	

	public TestData() {
		ninetynineccwise = createTestRoute();
	}

	@Override
	public ArrayList<Bus> getCurrentLocationAllBusses() throws Exception {
		ArrayList<Bus> busses = new ArrayList<Bus>();

		Bus b1 = new Bus("B1", "99C",b1lat , b1long+moveme , 0);
		Bus b2 = new Bus("B2", "116",b2lat+moveme, b2long , 0);
		Bus b3 = new Bus("B3", "117",b3lat-moveme ,b3long, 0);
		Bus b4 = new Bus("B4", "566", -34921481, 138602254, 0);

		moveme=moveme+50;

		busses.add(b1);
		busses.add(b2);
		busses.add(b3);
		busses.add(b4);

		//Bus b1 = new Bus("B1", "test", 034.90642740465981, 138.7335056061371, 0);

		//busses.add(b1);

		return busses;

	}

	@Override
	public ArrayList<Bus> getUserDefinesBusses(String routeID) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	//TODO: write a method to parse files with the routes in rather than having them in code
	public ArrayList<Route> getRoutes() throws Exception {
		//ArrayList<Route> routes = new ArrayList<Route>();
		//routes.add(ninetynineccwise);
		//return routes;
		return createRoutes();
	}

	@Override
	public ArrayList<BusStop> getStops() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	private Route createTestRoute() {
		//Log.d("debug","Creating test route");
		Route r = new Route("99CC","99C Clockwise");

		r.addStop(new BusStop("1","1",degreesToGeoPoint(-34.9287620,138.6001468)));
		//Log.d("debug","Added first bus stop!");
		r.addStop(new BusStop("2","2",degreesToGeoPoint(-34.9289203,138.5965633)));
		r.addStop(new BusStop("3","3",degreesToGeoPoint(-34.9281638,138.5937524)));
		r.addStop(new BusStop("4","4",degreesToGeoPoint(-34.9235369,138.5896969)));
		r.addStop(new BusStop("5","5",degreesToGeoPoint(-34.9236248,138.5878944)));

		r.addPathPoint(degreesToGeoPoint(-34.9284013,138.6060047));
		r.addPathPoint(degreesToGeoPoint(-34.9290523,138.5938704));
		r.addPathPoint(degreesToGeoPoint(-34.9260967,138.5936719));
		r.addPathPoint(degreesToGeoPoint(-34.9261187,138.5930496));
		r.addPathPoint(degreesToGeoPoint(-34.9246628,138.5929477));
		r.addPathPoint(degreesToGeoPoint(-34.9237348,138.5934252));
		r.addPathPoint(degreesToGeoPoint(-34.9233082,138.5933930));
		r.addPathPoint(degreesToGeoPoint(-34.9236248,138.5872722));
		r.addPathPoint(degreesToGeoPoint(-34.9221998,138.5870951));
		r.addPathPoint(degreesToGeoPoint(-34.9209594,138.6108166));
		r.addPathPoint(degreesToGeoPoint(-34.9238448,138.6110795));
		r.addPathPoint(degreesToGeoPoint(-34.9241526,138.6057365));
		r.addPathPoint(degreesToGeoPoint(-34.9284013,138.6060047));

		return r;
	}

	private ArrayList<Route> createRoutes() {
		ArrayList<Route> rs = new ArrayList<Route>();

		Route r = new Route("99C","99C Clockwise");

		r.addStop(new BusStop("1","1",degreesToGeoPoint(-34.9287620,138.6001468)));
		//Log.d("debug","Added first bus stop!");
		r.addStop(new BusStop("2","2",degreesToGeoPoint(-34.9289203,138.5965633)));
		r.addStop(new BusStop("3","3",degreesToGeoPoint(-34.9281638,138.5937524)));
		r.addStop(new BusStop("4","4",degreesToGeoPoint(-34.9235369,138.5896969)));
		r.addStop(new BusStop("5","5",degreesToGeoPoint(-34.9236248,138.5878944)));

		r.addPathPoint(degreesToGeoPoint(-34.9284013,138.6060047));
		r.addPathPoint(degreesToGeoPoint(-34.9290523,138.5938704));
		r.addPathPoint(degreesToGeoPoint(-34.9260967,138.5936719));
		r.addPathPoint(degreesToGeoPoint(-34.9261187,138.5930496));
		r.addPathPoint(degreesToGeoPoint(-34.9246628,138.5929477));
		r.addPathPoint(degreesToGeoPoint(-34.9237348,138.5934252));
		r.addPathPoint(degreesToGeoPoint(-34.9233082,138.5933930));
		r.addPathPoint(degreesToGeoPoint(-34.9236248,138.5872722));
		r.addPathPoint(degreesToGeoPoint(-34.9221998,138.5870951));
		r.addPathPoint(degreesToGeoPoint(-34.9209594,138.6108166));
		r.addPathPoint(degreesToGeoPoint(-34.9238448,138.6110795));
		r.addPathPoint(degreesToGeoPoint(-34.9241526,138.6057365));
		r.addPathPoint(degreesToGeoPoint(-34.9284013,138.6060047));

		Route n = new Route("116", "116");

		n.addPathPoint(degreesToGeoPoint(-34.921332,138.605495));
		n.addPathPoint(degreesToGeoPoint(-34.924139,138.605745));
		n.addPathPoint(degreesToGeoPoint(-34.924490,138.599685));
		n.addPathPoint(degreesToGeoPoint(-34.927270,138.599895));
		n.addPathPoint(degreesToGeoPoint(-34.928378,138.599145));
		n.addPathPoint(degreesToGeoPoint(-34.928857,138.599165));
		n.addPathPoint(degreesToGeoPoint(-34.929416,138.587795));
		n.addPathPoint(degreesToGeoPoint(-34.922590,138.587245));
		n.addPathPoint(degreesToGeoPoint(-34.922326,138.587445));
		n.addPathPoint(degreesToGeoPoint(-34.922133,138.589365));
		n.addPathPoint(degreesToGeoPoint(-34.921332,138.605495));

		rs.add(r);
		rs.add(n);

		Route q = new Route("117","117");

		q.addPathPoint(degreesToGeoPoint(-34.923857,138.593525));
		q.addPathPoint(degreesToGeoPoint(-34.924473,138.594195));
		q.addPathPoint(degreesToGeoPoint(-34.924693,138.594295));
		q.addPathPoint(degreesToGeoPoint(-34.924402,138.599685));
		q.addPathPoint(degreesToGeoPoint(-34.921623,138.599445));
		q.addPathPoint(degreesToGeoPoint(-34.921939,138.593385));
		q.addPathPoint(degreesToGeoPoint(-34.917627,138.593092));
		q.addPathPoint(degreesToGeoPoint(-34.915955,138.593028));
		q.addPathPoint(degreesToGeoPoint(-34.915564,138.593070));
		q.addPathPoint(degreesToGeoPoint(-34.915071,138.593210));
		q.addPathPoint(degreesToGeoPoint(-34.914271,138.593580));
		q.addPathPoint(degreesToGeoPoint(-34.913822,138.593709));
		q.addPathPoint(degreesToGeoPoint(-34.913417,138.593709));
		q.addPathPoint(degreesToGeoPoint(-34.912755,138.593537));
		q.addPathPoint(degreesToGeoPoint(-34.908391,138.591975));
		q.addPathPoint(degreesToGeoPoint(-34.908576,138.591155));
		q.addPathPoint(degreesToGeoPoint(-34.906675,138.590475));
		q.addPathPoint(degreesToGeoPoint(-34.906455,138.591295));
		q.addPathPoint(degreesToGeoPoint(-34.906385,138.592035));
		q.addPathPoint(degreesToGeoPoint(-34.908206,138.592795));
		q.addPathPoint(degreesToGeoPoint(-34.908391,138.591975));
		q.addPathPoint(degreesToGeoPoint(-34.912755,138.593537));
		q.addPathPoint(degreesToGeoPoint(-34.913417,138.593709));
		q.addPathPoint(degreesToGeoPoint(-34.913822,138.593709));
		q.addPathPoint(degreesToGeoPoint(-34.914271,138.593580));
		q.addPathPoint(degreesToGeoPoint(-34.915071,138.593210));
		q.addPathPoint(degreesToGeoPoint(-34.915564,138.593070));
		q.addPathPoint(degreesToGeoPoint(-34.915955,138.593028));
		q.addPathPoint(degreesToGeoPoint(-34.917627,138.593092));
		q.addPathPoint(degreesToGeoPoint(-34.921939,138.593385));
		q.addPathPoint(degreesToGeoPoint(-34.923857,138.593525));

		rs.add(q);
		
		return rs;
	}

	//FIXME: no checks for bad input - MAJOR WARNING - NEED TO DO ROBUST INPUT CHECKING
	//Helper method to convert double latitude and longitude into GeoPoint
	private GeoPoint degreesToGeoPoint(double lat, double lon) {

		Double latitude = lat * 1000000;
		Double longitude = lon * 1000000;

		int glat = latitude.intValue();
		int glon = longitude.intValue();

		/*Log.d("debug","New latitude:" + glat + " old: " + lat);
		Log.d("debug","New longitude: " + glon + " old: " + lon);*/

		return new GeoPoint(glat,glon);
	}

}
